<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户详情 - 权限管理系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <style>
        .gradient-bg {
            background: linear-gradient(135deg, #4361ee, #3f37c9);
        }

        .info-card {
            border: none;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.08);
        }

        .user-avatar {
            width: 80px;
            height: 80px;
            background: linear-gradient(45deg, #4361ee, #4895ef);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 2rem;
            margin: 0 auto;
        }

        .detail-item {
            padding: 12px 0;
            border-bottom: 1px solid #eee;
        }

        .detail-item:last-child {
            border-bottom: none;
        }

        .role-badge {
            background: linear-gradient(45deg, #4895ef, #4361ee);
            color: white;
            padding: 8px 15px;
            border-radius: 20px;
            margin: 5px;
            display: inline-block;
        }
    </style>
</head>
<body>
<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-dark gradient-bg shadow">
    <div class="container">
        <a class="navbar-brand" href="${pageContext.request.contextPath}/">
            <i class="bi bi-shield-lock-fill me-2"></i>权限管理系统
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <a class="nav-link" href="${pageContext.request.contextPath}/">
                        <i class="bi bi-house-door me-1"></i>首页
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="${pageContext.request.contextPath}/users">
                        <i class="bi bi-people me-1"></i>用户管理
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="${pageContext.request.contextPath}/roles">
                        <i class="bi bi-person-badge me-1"></i>角色管理
                    </a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<!-- 主内容 -->
<div class="container my-5">
    <c:choose>
        <c:when test="${not empty user}">
            <!-- 用户基本信息 -->
            <div class="card info-card mb-4">
                <div class="card-header bg-white">
                    <div class="d-flex justify-content-between align-items-center">
                        <h4 class="card-title mb-0 text-primary">
                            <i class="bi bi-person-badge me-2"></i>用户基本信息
                        </h4>
                        <span class="badge bg-primary fs-6">ID: ${user.id}</span>
                    </div>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-3 text-center mb-4">
                            <div class="user-avatar">
                                <i class="bi bi-person-fill"></i>
                            </div>
                            <h5 class="mt-3 mb-1">${user.name}</h5>
                            <p class="text-muted">${user.loginname}</p>
                            <c:choose>
                                <c:when test="${user.status == 0}">
                                    <span class="badge bg-success fs-6">启用</span>
                                </c:when>
                                <c:when test="${user.status == 1}">
                                    <span class="badge bg-danger fs-6">禁用</span>
                                </c:when>
                            </c:choose>
                        </div>
                        <div class="col-md-9">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="detail-item">
                                        <strong><i class="bi bi-envelope me-2 text-primary"></i>邮箱:</strong>
                                        <span class="float-end">${not empty user.email ? user.email : '未设置'}</span>
                                    </div>
                                    <div class="detail-item">
                                        <strong><i class="bi bi-telephone me-2 text-primary"></i>手机号:</strong>
                                        <span class="float-end">${not empty user.mobilephone ? user.mobilephone : '未设置'}</span>
                                    </div>
                                    <div class="detail-item">
                                        <strong><i class="bi bi-gender-ambiguous me-2 text-primary"></i>性别:</strong>
                                        <span class="float-end">
                                                <c:choose>
                                                    <c:when test="${user.sex == 1}">男</c:when>
                                                    <c:when test="${user.sex == 2}">女</c:when>
                                                    <c:otherwise>未设置</c:otherwise>
                                                </c:choose>
                                            </span>
                                    </div>
                                </div>
                                <div class="col-md-6">
                                    <div class="detail-item">
                                        <strong><i class="bi bi-telephone-forward me-2 text-primary"></i>电话:</strong>
                                        <span class="float-end">${not empty user.tel ? user.tel : '未设置'}</span>
                                    </div>
                                    <div class="detail-item">
                                        <strong><i class="bi bi-geo-alt me-2 text-primary"></i>地址:</strong>
                                        <span class="float-end">${not empty user.address ? user.address : '未设置'}</span>
                                    </div>
                                    <div class="detail-item">
                                        <strong><i class="bi bi-calendar me-2 text-primary"></i>创建时间:</strong>
                                        <span class="float-end">${user.createTime}</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 用户角色信息 -->
            <div class="card info-card">
                <div class="card-header bg-white">
                    <h4 class="card-title mb-0 text-primary">
                        <i class="bi bi-shield-check me-2"></i>角色信息
                    </h4>
                </div>
                <div class="card-body">
                    <c:choose>
                        <c:when test="${not empty user.roles}">
                            <div class="row">
                                <c:forEach var="role" items="${user.roles}">
                                    <div class="col-md-6 mb-3">
                                        <div class="card border-0 shadow-sm">
                                            <div class="card-body">
                                                <div class="d-flex justify-content-between align-items-start">
                                                    <div>
                                                        <h6 class="card-title mb-1">
                                                            <i class="bi bi-person-badge me-2 text-warning"></i>${role.name}
                                                        </h6>
                                                        <p class="card-text text-muted small mb-2">${role.description}</p>
                                                    </div>
                                                    <span class="badge ${role.status == 0 ? 'bg-success' : 'bg-danger'}">
                                                            ${role.status == 0 ? '启用' : '禁用'}
                                                    </span>
                                                </div>
                                                <div class="mt-2">
                                                    <small class="text-muted">
                                                        <i class="bi bi-calendar me-1"></i>创建: ${role.createTime}
                                                    </small>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </c:forEach>
                            </div>
                        </c:when>
                        <c:otherwise>
                            <div class="text-center py-4">
                                <i class="bi bi-info-circle display-4 text-muted mb-3"></i>
                                <h5 class="text-muted">该用户暂无角色</h5>
                                <p class="text-muted">请为用户分配相应的角色</p>
                            </div>
                        </c:otherwise>
                    </c:choose>
                </div>
            </div>
        </c:when>
        <c:otherwise>
            <!-- 用户不存在 -->
            <div class="card info-card">
                <div class="card-body text-center py-5">
                    <i class="bi bi-exclamation-triangle display-1 text-warning mb-3"></i>
                    <h3 class="text-warning">用户不存在</h3>
                    <p class="text-muted mb-4">未找到指定的用户信息，请检查用户名是否正确</p>
                    <a href="${pageContext.request.contextPath}/users" class="btn btn-primary">
                        <i class="bi bi-arrow-left me-2"></i>返回用户列表
                    </a>
                </div>
            </div>
        </c:otherwise>
    </c:choose>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>